<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>9-5</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .bigdiv {
            height: 400px;
            width: 300px;
            border: 1px solid red;
            margin: 30px 30px;
        }
        
        .smalldiv {
            height: 50px;
            width: 50px;
            background-color: pink;
            position: absolute;
            left: 30px;
        }
    </style>
</head>

<body>
    <div class="bigdiv">
        <div class="smalldiv"></div>
    </div>
    <script>
        var bigdiv = document.querySelector('.bigdiv');
        var pink = document.querySelector('.smalldiv');
        /*  pink.addEventListener('mousedown', function(e) {

         }) */
        pink.addEventListener('mousemove', function(e) {
            var x = e.pageX - bigdiv.offsetLeft;
            var y = e.pageY - bigdiv.offsetTop;
            pink.style.left = x + 'px';
            pink.style.top = y + 'px';
            /* px掉了就错了 */
        })
    </script>
</body>

</html>